﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TShockAPI;

namespace BuffPrefixV2
{
    public static class ConfigUtils
    {
        public static string configDir = TShock.SavePath + "/BuffPrefix";
        public static string configPath = configDir + "/config.json";
        public static Config config = new Config();
        /// <summary>
        /// 配置文件的读取
        /// </summary>
        public static  void ReadConfig() {
            if (Directory.Exists(configDir))
            {
                if (File.Exists(configPath))
                {
                    config = JsonConvert.DeserializeObject<Config>(File.ReadAllText(configPath));
                }
                else
                {
                    File.WriteAllText(configPath, JsonConvert.SerializeObject(config, Formatting.Indented));
                }
            }
            else {
                Directory.CreateDirectory(configDir);
                File.WriteAllText(configPath, JsonConvert.SerializeObject(config, Formatting.Indented));
            }
        }
        public static void UpdateConfig() {
            File.WriteAllText(configPath, JsonConvert.SerializeObject(config, Formatting.Indented));
        }
    }
    public class Config { 
        public Prefix DefaultPrefix { get; set; }
        public bool API { get; set; }
        public Config() 
        {
            DefaultPrefix = new Prefix(0,"无称号",new List<int>() );
            API = false;
        }
    }
}
